package org.platform.processor.diagnose;

import com.mc.mic.core.tool.helper.SpringContextHelper;
import lombok.extern.slf4j.Slf4j;
import org.platform.constant.DiagnoseConst;
import org.platform.processor.diagnose.impl.FaultTreeDiagnoseImpl;
import org.platform.processor.diagnose.impl.TaskFaultDiagnoseImpl;
import org.platform.processor.diagnose.impl.TestFaultDiagnoseImpl;

/**
 * 该类主要是获取对应诊断类型执行类,让该类去执行故障诊断流程
 * 这里根据懒汉式创建单例
 *
 * @author
 */
@Slf4j
public class DiagnoseFactorySingleton {
    private static DiagnoseFactorySingleton diagnoseFactorySingleton;

    private DiagnoseFactorySingleton() {
    }

    public static DiagnoseFactorySingleton getInstance() {
        if (null == diagnoseFactorySingleton) {
            synchronized (DiagnoseFactorySingleton.class) {
                if (null == diagnoseFactorySingleton) {
                    diagnoseFactorySingleton = new DiagnoseFactorySingleton();
                }
            }
        }
        return diagnoseFactorySingleton;
    }

    /**
     * 根据任务器里面的诊断类型,返回对应的执行器
     *
     * @param diagnoseType
     * @return
     */
    IDiagnoseExecutor getExecutor(int diagnoseType) {
        IDiagnoseExecutor iDiagnoseExecutor;

        switch (diagnoseType) {
            case DiagnoseConst.DIAGNOSE_TYPE_TASK_FAULT:
                iDiagnoseExecutor = SpringContextHelper.getBean(TaskFaultDiagnoseImpl.class);
                break;
            case DiagnoseConst.DIAGNOSE_TYPE_TEST_FAULT:
                iDiagnoseExecutor = SpringContextHelper.getBean(TestFaultDiagnoseImpl.class);
                break;
            default:
                iDiagnoseExecutor = SpringContextHelper.getBean(FaultTreeDiagnoseImpl.class);
        }
        return iDiagnoseExecutor;
    }
}
